#ifndef __APPLE_INCLUDE_DICTIONARY_H__
#define __APPLE_INCLUDE_DICTIONARY_H__

#include <sysdep.h>
#include <list.h>


typedef struct _apple_dict_t apple_dict_t;

/* file suffix */
#define IFO_FILE	"ifo"
#define IDX_FILE	"idx"
#define DICT_FILE	"dict"

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

struct _apple_dict_t {
	/* basename */
	const char *name;

	uint32_t words_count;		/* total words count */
	uint32_t idx_size;		/* uncompressed idx file size */
	uint32_t origdict_size;		/* uncompressed dict file size */
	int dict_type;
#define DICT_UNKNOWN    0
#define DICT_TEXT       1
#define DICT_GZIP       2
#define DICT_DZIP       3

	int stq;	/* XXX: sametypesequence option */
	/* buffer size is words_count and store words' offset in dict file */
	uint32_t *idxbuff;
	int fd_ifo;
	int fd_idx;
	int fd_dict;

	list_t link;
};

int apple_dict_init(void);
void apple_dict_exit(void);


/* dictionary common api */
apple_dict_t *apple_find_dict(const char *name);
int get_word_explain(const char *word, char *output_buf);
/* rabbish */
int get_all_words_in_dict(void *up_data, char *output_buf);
uint32_t get_word_by_idx(apple_dict_t *dict, uint32_t idx, char *outbuf);

uint32_t find_word_in_idxfile(apple_dict_t *dict, const char *word);
int get_word_meaning_in_dict(apple_dict_t *dict, const char *word, 
			uint32_t index, char *output_buf);
int parse_ifo_file(apple_dict_t *dict);
int parse_idx_file(apple_dict_t *dict);
int open_dict_files(apple_dict_t *dict);

#endif /* __APPLE_INCLUDE_MODULE_H__ */
